{
  "properties" : { },
  "id" : "020b774496e040049fe00065c214ff3c",
  "script" : null,
  "groupId" : "e6cd7933a0e746b8b4af97af80c9c45c",
  "name" : "查询",
  "createTime" : null,
  "updateTime" : 1728705707907,
  "lock" : null,
  "createBy" : null,
  "updateBy" : null,
  "path" : "/search",
  "method" : "POST",
  "parameters" : [ ],
  "options" : [ ],
  "requestBody" : "{\r\n    \"tn\": \"tb_res_staff\",\r\n    \"data\":{}\r\n}",
  "headers" : [ ],
  "paths" : [ ],
  "responseBody" : "{\n    \"msg\": \"success\",\n    \"data\": {\n        \"total\": 3,\n        \"items\": [\n            {\n                \"id\": \"1844191674306158594\",\n                \"createBy\": \"admin\",\n                \"createTime\": \"2024-10-10 09:42:13\",\n                \"updateBy\": null,\n                \"updateTime\": null,\n                \"isAuthSign\": \"N\",\n                \"age\": null,\n                \"avatar\": null,\n                \"birthday\": null,\n                \"documentType\": null,\n                \"education\": null,\n                \"email\": null,\n                \"gender\": null,\n                \"graduateInstitutions\": null,\n                \"idNumber\": null,\n                \"major\": \"1\",\n                \"name\": \"18611566565\",\n                \"phone\": null,\n                \"post\": null,\n                \"remark\": null,\n                \"signaturePic\": null,\n                \"specificPositions\": \"N\"\n            },\n            {\n                \"id\": \"1843950158899838977\",\n                \"createBy\": \"admin\",\n                \"createTime\": \"2024-10-09 17:42:31\",\n                \"updateBy\": \"admin\",\n                \"updateTime\": \"2024-10-10 08:59:46\",\n                \"isAuthSign\": \"N\",\n                \"age\": \"\",\n                \"avatar\": \"\",\n                \"birthday\": null,\n                \"documentType\": \"\",\n                \"education\": \"\",\n                \"email\": \"\",\n                \"gender\": \"1\",\n                \"graduateInstitutions\": \"\",\n                \"idNumber\": \"\",\n                \"major\": \"\",\n                \"name\": \"zhangsan\",\n                \"phone\": \"\",\n                \"post\": \"\",\n                \"remark\": \"\",\n                \"signaturePic\": \"\",\n                \"specificPositions\": \"N\"\n            },\n            {\n                \"id\": \"1843950127727771649\",\n                \"createBy\": \"admin\",\n                \"createTime\": \"2024-10-09 17:42:24\",\n                \"updateBy\": \"admin\",\n                \"updateTime\": \"2024-10-10 09:33:38\",\n                \"isAuthSign\": \"N\",\n                \"age\": \"\",\n                \"avatar\": \"\",\n                \"birthday\": null,\n                \"documentType\": \"\",\n                \"education\": \"\",\n                \"email\": \"\",\n                \"gender\": \"2\",\n                \"graduateInstitutions\": \"\",\n                \"idNumber\": \"\",\n                \"major\": \"\",\n                \"name\": \"ceshi\",\n                \"phone\": \"\",\n                \"post\": \"\",\n                \"remark\": \"\",\n                \"signaturePic\": \"\",\n                \"specificPositions\": \"N\"\n            }\n        ]\n    },\n    \"status\": 0\n}",
  "description" : null,
  "requestBodyDefinition" : null,
  "responseBodyDefinition" : {
    "name" : "",
    "value" : "",
    "description" : "",
    "required" : false,
    "dataType" : "Object",
    "type" : null,
    "defaultValue" : null,
    "validateType" : "",
    "error" : "",
    "expression" : "",
    "children" : [ {
      "name" : "success",
      "value" : "false",
      "description" : "",
      "required" : false,
      "dataType" : "Boolean",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "message",
      "value" : "Token失效，请重新登录!",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "code",
      "value" : "401",
      "description" : "",
      "required" : false,
      "dataType" : "Integer",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "result",
      "value" : "null",
      "description" : "",
      "required" : false,
      "dataType" : "Object",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "timestamp",
      "value" : "1728702472263",
      "description" : "",
      "required" : false,
      "dataType" : "Long",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    } ]
  }
}
================================
import cn.hutool.core.util.StrUtil
import log

var camelToUnderline = (str)=> {
    StringBuilder result = new StringBuilder();
    for (i in range(0,str.length()-1)) {
        char c = str.charAt(i);
        if (Character.isUpperCase(c) && i > 0) {
            result.append("_");
        }
        result.append(Character.toLowerCase(c));
    }
    return result.toString();
}
var tn = body.tn
var data = body.data
var wheres = body.wheres || ""
var cinfo = db.select("""
    SELECT DATA_TYPE dtype,CHARACTER_MAXIMUM_LENGTH mlength,COLUMN_NAME cname,
        COLUMN_COMMENT ccomment,IS_NULLABLE isnull
    FROM information_schema.COLUMNS
    WHERE TABLE_SCHEMA = database() AND TABLE_NAME = #{tn};
""")
for (key,value in data) {
    for (c in cinfo) {
        if (c.cname.equals(camelToUnderline(key))){
            log.info("cname:{},key:{},value:{}",c.cname,key,value)
            if (value){
                var columnName = camelToUnderline(key)
                if (c.dtype.equals("date") || c.dtype.equals("datetime")){
                    var arr = String.valueOf(value).split(",")
                    wheres += `  and date_format(${columnName},'%Y-%m-%d') between '${arr[0]}' and '${arr[1]}' `
                } else if (c.dtype.equals("int")){
                    wheres += `  and ${columnName}=${value} `
                } else {
                    wheres += `  and ${columnName} like concat('%','${value}','%') `
                }
            }
        }
    }
}

var result = db.page("""
    select * from ${tn} where 1=1
    ${wheres}
    order by create_time desc
""")
// return result
var index = 0
var getIndex = ()=>{
    index++
    return index
}
result.items = select getIndex() index,i.* from result.items i
exit 0, "",result;
// return result